const Controller = require('../../core/controller/ApiController');
const { Route, HttpPost, Middleware, filters } = require('../../../plugin/egg-decorator-router');
const { ExceptionHandler } = require('../../../plugin/egg-controller-exception-handler/lib');
const path = require('path');

@Route("/api/upload/audio")
class UploadCtrl extends Controller{

    @HttpPost("/single")
    @ExceptionHandler()
    async UploadAudio(){
        const rule = {
            'files': 'array'
        };
        this.validate(rule, this.ctx.request);
        const file = this.ctx.request.files[0];
        const extname = path.extname(file.filename);
        if(extname !== '.mp3'){
            throw new this.error.InvalidError('文件类型必须为 mp3！');
        }
        this.result.data = await this.service.upload.audio.singleAudio(file);
    }

}
module.exports = UploadCtrl;
